import os
from shutil import copyfile

person_datasets_save_path = 'E:/datasets/person_train_datasets/'
bg_datasets_save_path = 'E:/datasets/bg_train_datasets/'
person_train_path = 'E:/datasets/person/'
bg_train_path = 'E:/datasets/background/'

# for root, dirs, files in os.walk(person_train_path, topdown=True):
#     for name in files:
#         if name[-3:]=='png':
#             continue
#         ID  = name.split('_')
#         src_path = person_train_path + '/' + name
#         dst_path = person_datasets_save_path + '/' + ID[0]
#         if not os.path.isdir(dst_path):
#             os.mkdir(dst_path)
#         copyfile(src_path, dst_path + '/' + name)


for root, dirs, files in os.walk(bg_train_path, topdown=True):
    for name in files:
        if name[-3:]=='png':
            continue
        ID  = name.split('_')
        src_path = bg_train_path + '/' + name
        dst_path = bg_datasets_save_path + '/' + ID[0]
        if not os.path.isdir(dst_path):
            os.mkdir(dst_path)
        copyfile(src_path, dst_path + '/' + name)